fangimjs.define("util/util", [], function (require, exports, module) {
    // 引入依赖
    var Util = function () {
        //在这里定义变量
    };
    //在这里定义函数
    Util.prototype.getCookie = function (name) {
        var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
        if (arr = document.cookie.match(reg)) {
            return decodeURIComponent(arr[2]);
        } else {
            return '';
        }
    };
    Util.prototype.setCookie = function (name, value, days) {
        var expires = '';
        if(days) {
            var exp = new Date();
            isNaN(days) && (days = 3);
            exp.setTime(exp.getTime() + days * 24 * 60 * 60 * 1000);
            expires = exp.toGMTString();
        }
        document.cookie = name + "=" + encodeURIComponent(value) + "; path=/; expires=" + expires;
    };
    Util.prototype.encodeString = function (str) {
        var p = new RegExp("<","g");
        str = str.replace(p, "&lt;");
        p = new RegExp(">","g");
        str = str.replace(p, "&gt;");
        return str;
    };
    Util.prototype.getGUID = function () {
        var i = 0;
        var result = "";
        var pattern = "0123456789abcdef";
        for (i = 0; i<8; i++)
        {
            result += pattern.charAt(Math.round(Math.random() * 15));
        }
        var time = new Date().getTime();
        result += ("00000000" + time.toString(16).toLocaleLowerCase()).substr(-8);
        return result;
    };

    /**
     * debug 模式：打印信息，记录日志
     * yf: debug 模式 从 imdebug 变为 debug
     */
    Util.prototype.trace = function () {
        if(this.debug === undefined) {
            this.debug = window.location.href.indexOf('debug') > -1;
        }
        if(this.debug){
            console.log(Array.prototype.join.call(arguments,' | '))
        }
    };
    // 暴露对应接口
    module.exports = new Util();
});
